/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.acq.web.plantinfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.acq.entity.plantinfo.AcqPlantInfo;
import com.thinkgem.jeesite.modules.acq.service.plantinfo.AcqPlantInfoService;

/**
 * 种植品信息Controller
 * @author lj
 * @version 2018-04-16
 */
@Controller
@RequestMapping(value = "${adminPath}/acq/plantinfo/acqPlantInfo")
public class AcqPlantInfoController extends BaseController {

	@Autowired
	private AcqPlantInfoService acqPlantInfoService;
	
	@ModelAttribute
	public AcqPlantInfo get(@RequestParam(required=false) String id) {
		AcqPlantInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = acqPlantInfoService.get(id);
		}
		if (entity == null){
			entity = new AcqPlantInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("acq:plantinfo:acqPlantInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(AcqPlantInfo acqPlantInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<AcqPlantInfo> page = acqPlantInfoService.findPage(new Page<AcqPlantInfo>(request, response), acqPlantInfo); 
		model.addAttribute("page", page);
		return "modules/acq/plantinfo/acqPlantInfoList";
	}

	@RequiresPermissions("acq:plantinfo:acqPlantInfo:view")
	@RequestMapping(value = "form")
	public String form(AcqPlantInfo acqPlantInfo, Model model) {
		model.addAttribute("acqPlantInfo", acqPlantInfo);
		return "modules/acq/plantinfo/acqPlantInfoForm";
	}

	@RequiresPermissions("acq:plantinfo:acqPlantInfo:edit")
	@RequestMapping(value = "save")
	public String save(AcqPlantInfo acqPlantInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, acqPlantInfo)){
			return form(acqPlantInfo, model);
		}
		acqPlantInfoService.save(acqPlantInfo);
		addMessage(redirectAttributes, "保存种植品信息成功");
		return "redirect:"+Global.getAdminPath()+"/acq/plantinfo/acqPlantInfo/?repage";
	}
	
	@RequiresPermissions("acq:plantinfo:acqPlantInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(AcqPlantInfo acqPlantInfo, RedirectAttributes redirectAttributes) {
		acqPlantInfoService.delete(acqPlantInfo);
		addMessage(redirectAttributes, "删除种植品信息成功");
		return "redirect:"+Global.getAdminPath()+"/acq/plantinfo/acqPlantInfo/?repage";
	}

}